<template>
 <view class="main">
   <view class="logo">
	 <view class="ilist" @click="myitem">
	    <image src="https://ppp.new.zeroitem.cn/ppp/menu.png" style="width:64rpx;height:64rpx"></image>
	 </view>
	 <image src="https://ppp.new.zeroitem.cn/ppp/logo.png" class="imglog"></image>   
   </view>
   <view class="menu">
      根据时间情况，设置工作区域与时间 
   </view>
   
   <view class="part1" :class="tmode==2?'adclass1':''">
	 <view class="p1-1" v-if="tmode!=2" @click="smodel(2)">
	  <image src="https://ppp.new.zeroitem.cn/ppp/sarrow1.png" class="p1-1-1"></image>
	  <view class="p1-1-2">接单类型</view>   
	 </view> 
	 <view class="pm-1" v-if="tmode==2" @click="smodel(2)">
       <view class="pm-1-1">
		<image src="https://ppp.new.zeroitem.cn/ppp/sarrow2.png" class="pm1"></image>
		<view class="pm2">接单类型</view>    
	   </view>   
	   <view class="pm-1-2 adc1">
		 普通单(刚注册的拍手默认接普通单) <radio value="r1"  color="#949DE1" class="rd" :checked="r1==1" @click="setr(1)"/>
	   </view>
	   <view class="pm-1-2 adc2">
		 实习单 <radio value="r2"  color="#949DE1" class="rd" :checked="r2==1" @click="setr(2)"/>
	   </view>	   
	   <view class="pm-1-2 adc2">
		 达人单(需要经过平台资格审核) <radio value="r3"  color="#949DE1" class="rd" :checked="r3==1" @click="setr(3)"/>
	   </view>		   
	 </view>
		  
	 <view class="p1-1" v-if="tmode!=3" @click="smodel(3)">
	  <image src="https://ppp.new.zeroitem.cn/ppp/sarrow1.png" class="p1-1-1"></image>
	  <view class="p1-1-2">工作状态</view>   
	 </view> 
	
	<view class="pm-1 adclass2" v-if="tmode==3" @click="smodel(3)">
	  <view class="pm-1-1">
			<image src="https://ppp.new.zeroitem.cn/ppp/sarrow2.png" class="pm1"></image>
			<view class="pm2">工作状态</view>    
	  </view>
	  <radio-group @change="radioChange1">
	  <view class="pm-1-2 adc1">
			 全职（接单公里范围更大些） <radio value="1"  color="#949DE1" class="rd" :checked="gzzt==1"/>
	  </view>
	  <view class="pm-1-2 adc2">
			 兼职（适合时间不固定的拍手） <radio value="2"  color="#949DE1" class="rd" :checked="gzzt==2"/>
	  </view>	   		   
	 </radio-group>
	</view>
	
	 <view class="p1-1" v-if="tmode!=4 && gzzt==2" @click="smodel(4)">
	  <image src="https://ppp.new.zeroitem.cn/ppp/sarrow1.png" class="p1-1-1"></image>
	  <view class="p1-1-2">工作时间</view>   
	 </view> 		  
   <view class="pm-1" v-if="tmode==4 && gzzt==2" @click="smodel(4)">
	  <view class="pm-1-1">
			<image src="https://ppp.new.zeroitem.cn/ppp/sarrow2.png" class="pm1"></image>
			<view class="pm2">工作时间</view>    
	  </view>

	  <view class="pm-1-2 adc1">
		下班接单 <radio value="1"  color="#949DE1" class="rd" :checked="gzsj1==1"  @click="sgzsj(1)" />
		（接工作日晚单）
	  </view>
	  <view class="pm-1-2 adc2">
	    周末接单 <radio value="2"  color="#949DE1" class="rd" :checked="gzsj2==1"  @click="sgzsj(2)"/>
		（接六日全天单）
	  </view>
	  <view class="pm-1-2 adc2" style="height:62rpx;margin-top:20rpx;">
	    自定义单 <radio value="3"  color="#949DE1" class="rd" :checked="gzsj3==1" @click="sgzsj(3)"/>
		<image src="https://ppp.new.zeroitem.cn/ppp/rq.png" class="rcal" @click="
		rlpd()"></image>
		日历排档
	  </view>					 
				 
	
	</view>	
		
	 <view class="p1-1" v-if="tmode!=5" @click="smodel(5)">
	  <image src="https://ppp.new.zeroitem.cn/ppp/sarrow1.png" class="p1-1-1"></image>
	  <view class="p1-1-2">地点区间</view>   
	 </view> 
		 
   <view class="pm-1 adm4" v-if="tmode==5" @click="smodel(5)">
	  <view class="pm-1-1">
			<image src="https://ppp.new.zeroitem.cn/ppp/sarrow2.png" class="pm1"></image>
			<view class="pm2">地点区间</view>    
	  </view>
	  <view class="dw" @click="dingwei">
		<view class="dw1">定位</view> 
		<image src="https://ppp.new.zeroitem.cn/ppp/ps/3.png" class="img1"></image>
		<view class="dw2">{{address}}</view>
	  </view>
	  <view class="dw">选择距离</view>
	  <view class="tju2" :style="{'padding-left': dt+'rpx'}">{{nd}}km</view>
	  <view class="tju flex_comm">
		  <view class="dot"></view>
		  <slider :value="nd" @change="sliderChange" min="0" max="30" block-size="12" class="sbar"/>
		  <view class="dot"></view>
	  </view>
	  <view class="tju1 flex_comm">
		  <view class="fm1">0km</view>
		  <view class="fm1 right">30km</view>
	  </view>	  
     
	</view>		  
   <view class="btnq" @click="addzt()">提交状态</view>	 
   </view>
  
</view>
</template>

<script>
	import {
		mapGetters,
		mapActions
	} from 'vuex'
	import {
		toLogin
	} from '@/utils/login'
	
	import {
		loadingFun,
		menuJump
	} from '@/utils/tools'	
	import {
	  psrz,psrzinfo,mycal,pscurorder
	} from '@/api/ppp'		
    import {
		loadingType
	} from '@/utils/type'
	
	const app = getApp()
	export default {
		data() {
			return {
	         tmode:0,
			 dt:63,
			 address:"请点击选择定位您的接单位置",
			 nd:5,
			 latitude:"",
			 longitude:"",
			 show: true,
			 mode: 'range',
			 rtype:1,
			 r1:0,
			 r2:0,
			 r3:0,
			 gzsj1:0,
			 gzsj2:0,
			 gzsj3:0,
			 gzzt:0,
			 gzsj:0,
			 cal1:[],
			 cal2:[],
			 sdate1:"",
			 sdatestr1:"",
			 sdate2:"",
			 sdatestr2:"",
			 curorder:[]
			}
		},
		onLoad() {
		 this.info();
		 //this.getcal();
		 //this.getpscurorder();
		},
		onShow() {
    
		},

		onReachBottom() {
	    
		},
		onPullDownRefresh() {

		},

		methods: {
	     jumpback(){
			  uni.navigateBack();
			},
		 rlpd(){
		  uni.navigateTo({
		  	url:"/pages/ppp/ps1/dyjd"
		  })
		 },
		 myitem(){
		  uni.navigateBack();	 
		 },
		 jumpdd(){
			   var oid=this.curorder.id;
				uni.navigateTo({
					url:"/pages/ppp/ps/order1?oid="+oid
				})	 
		 },
		 sliderChange(e){
		  var value=e.detail.value;
	      var m1=(value/30)*377;
		  this.dt=Math.ceil(m1);
		  this.nd=value;
		 },
		 stab(type){
		  this.rtype=type;	 
		 },
		 sgzsj(type){
		  if(type==3){this.gzsj3=1;this.gzsj1=0;this.gzsj2=0;}	
		  if(type==1){this.gzsj3=0;this.gzsj1=1;}	
		  if(type==2){this.gzsj3=0;this.gzsj2=1;}	
		 },
		 async info(){
		  var that=this;
		  const{
		  	code,
		  	msg,
		  	data,
		   }= await psrzinfo();
		   if(code==1){
              var psinfo=data.psinfo;
			  if(psinfo!=""){
			  that.r1=psinfo.r1;
			  that.r2=psinfo.r2;
			  that.r3=psinfo.r3;
			  that.gzzt=psinfo.gzzt;
			  that.gzsj=psinfo.gzsj;
			  that.gzsj1=psinfo.gzsj1;
			  that.gzsj2=psinfo.gzsj2;
			  that.gzsj3=psinfo.gzsj3;
			  var address=psinfo.address;
			  var dt=psinfo.dt;
			  var nd=psinfo.nd;
			  if(address=='' || address==undefined){
				address='请点击选择定位您的接单位置';  
				dt=63;nd=5;
			  }
			  that.address=address;
			  that.dt=dt;that.nd=nd;
			  that.latitude=psinfo.latitude;
			  that.longitude=psinfo.longitude;
			 }
		   }		 
          //const {pscurorder}=await pscurorder();
					   
		 },
		 async addzt(){
		   var that=this;
		   var r1=that.r1;var r2=that.r2;var r3=that.r3;
		   if(r1==0 && r2==0 && r3==0){
			 uni.showToast({title:"请选择接单类型",icon:"none"});
			 return false;   
		   }
		   var gzzt=that.gzzt;var gzsj=that.gzsj;
		   var gzsj1=that.gzsj1;
		   var gzsj2=that.gzsj2;
		   var gzsj3=that.gzsj3;
		   if(gzzt==0){
			uni.showToast({title:"请选择工作状态",icon:"none"});
			return false;     
		   }
		   if(gzzt==2){
			  if(gzsj1==0 && gzsj2==0 && gzsj3==0){
		   	  uni.showToast({title:"请选择工作时间",icon:"none"});
		   	  return false;  
			 }
		   }
		   var address=that.address;var nd=that.nd;var dt=that.dt;
		   var latitude=that.latitude;
		   var longitude=that.longitude;
		   if(latitude==''){
		   	  uni.showToast({title:"请定位选择您的工作地区",icon:"none"});
		   	  return false;     
		   }	
		   var odata={
			r1:r1,r2:r2,r3:r3,gzzt:gzzt,gzsj:gzsj,gzsj1:gzsj1,gzsj2:gzsj2,gzsj3:gzsj3,
			address:address,latitude:latitude,longitude:longitude,
			nd:nd,dt:dt,part:"psinfo"};
		   const{
		   	 code,
		     msg,
		     data,
		   }= await psrz(odata);
		   if(code==1){
			 uni.navigateTo({
			 	url:"/pages/ppp/ps/psrz"
			 })   
		   }	
		 },
		 
		 radioChange1(e){
		  var value=e.detail.value;
		  this.gzzt=value;
		 },
		 radioChange2(e){
		  var value=e.detail.value;
		  this.gzsj=value;
		 },		 
		 
		 smodel(type){
		  this.tmode=type; 
		 },
		 setr(type){
		  if(type==1){
			console.log(this.r1);
			if(this.r1==1){this.r1=0;return false;}
			if(this.r1==0){this.r1=1;return false;}
		  }
		  if(type==2){
			if(this.r2==1){this.r2=0;return false;}
			if(this.r2==0){this.r2=1;return false;}  
		  }
		  if(type==3){
			if(this.r3==1){this.r3=0;return false;}
			if(this.r3==0){this.r3=1;return false;} 
		  }
		 },
		 mymain(){
		   uni.navigateTo({
		   	url:"/pages/ppp/ps/main1"
		   })	 
		 },
	  
		 dddt(){
		   uni.navigateTo({
		   	url:"/pages/ppp/ps1/dddt"
		   })	 
		 },
		dingwei(){
			      var that=this;
					uni.chooseLocation({
						success:(res)=> {
						  console.log(res);
						  that.address=res.address;
						  that.latitude=res.latitude;
						  that.longitude=res.longitude;
						},
						
						fail:()=>{
							// 如果用uni.chooseLocation没有获取到地理位置，则需要获取当前的授权信息，判断是否有地理授权信息
							uni.getSetting({
								success: (res) => {
									var status = res.authSetting;
									if(!status['scope.userLocation']){
									// 如果授权信息中没有地理位置的授权，则需要弹窗提示用户需要授权地理信息
										uni.showModal({
											title:"是否授权当前位置",
											content:"需要获取您的地理位置，请确认授权，否则地图功能将无法使用",
											success:(tip)=>{
												if(tip.confirm){
												// 如果用户同意授权地理信息，则打开授权设置页面，判断用户的操作
													uni.openSetting({
														success:(data)=>{
														// 如果用户授权了地理信息在，则提示授权成功
															if(data.authSetting['scope.userLocation']===true){
																uni.showToast({
																	title:"授权成功",
																	icon:"success",
																	duration:1000
																})
																// 授权成功后，然后再次chooseLocation获取信息
																uni.chooseLocation({
																	success: (res) => {
																	that.address=res.address;
																	that.latitude=res.latitude;
																	that.longitude=res.longitude;
																	}
																})
															}else{
																uni.showToast({
																	title:"授权失败",
																	icon:"none",
																	duration:1000
																})
															}
														}
													})
												}
											}
										})
									}
								},
								fail: (res) => {
									uni.showToast({
										title:"调用授权窗口失败",
										icon:"none",
										duration:1000
									})
								}
							})
						}
					});
				}		 
		 
		 
		 
		 
		 
		 
		},
		computed: {
			...mapGetters(['isLogin']),
		}
	}
</script>

<style>
 @import "./setdqzz.css";	
</style>
